package org.csu.mypetstore.web.servlets;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import org.csu.mypetstore.service.CatalogService;
import org.csu.mypetstore.domain.Product;
public class SuspensionWindowServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String categoryId = req.getParameter("categoryId");
        System.out.println(categoryId+"             ddddddddd");
        CatalogService catalogService = new CatalogService();
        List<Product> productList = catalogService.getProductListByCategory(categoryId);
        String response = "Product ID      Name\n";
        int i = 0;
        while(i < productList.size()){
        Product product = productList.get(i);
        response += product.getProductId() + "      " + product.getName() + "\n";
        i++;
    }
    resp.setContentType("text/xml");
    PrintWriter out = resp.getWriter();
    out.print(response);
    out.flush();
    out.close();
    }
}
